package com.zhuiyun.project.api.frontPoetry.service.impl;
import com.zhuiyun.project.api.ancientPoetry.entity.Poetry;
import com.zhuiyun.project.api.frontPoetry.entity.FrontPoetry;
import com.zhuiyun.project.api.frontPoetry.mapper.FrontPoetryMapper;
import com.zhuiyun.project.api.frontPoetry.service.FrontPoetryService;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.RedisUtil;
import com.zhuiyun.project.utils.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description TODO
 * @Author shy
 * @Date 2023/12/18 10:55
 */
@Service
public class FrontPoetryServiceImpl implements FrontPoetryService {
    @Autowired
    private FrontPoetryMapper frontPoetryMapper;
    @Override
    public CommonResult FrontAllPoetry(PageRequest pageRequest, Integer pageStatus) {
        MybatisPageHelper.startPage(pageRequest);
        if(pageStatus==0){
            //新发首做   排序查询
            Example example=new Example(FrontPoetry.class);
            example.orderBy("creationTime").desc();
            List<FrontPoetry> ListPoetry = frontPoetryMapper.selectByExample(example);
            PageResult result= MybatisPageHelper.getPageResult(ListPoetry);
            return CommonResult.ok(result);
        }else if(pageStatus==1){
            //猜你喜欢
            return CommonResult.ok();
        }else if(pageStatus==2){
            //热榜推荐
            return CommonResult.ok();
        }else {
            return CommonResult.error(EmErrorCode.UNKNOW_ERROR);
        }
    }

    @Override
    public CommonResult FrontGetPoetry(Integer id) {
        if(id!=null&&id!=0){
            FrontPoetry f=new FrontPoetry();
            f.setPoetryId(id);
            FrontPoetry poetry=frontPoetryMapper.selectOne(f);
            if(poetry!=null){
                return CommonResult.ok(poetry);
            }else {
                return CommonResult.error(EmErrorCode.ID_NOT_OBJECT);
            }
        }else {
            return CommonResult.error(EmErrorCode.ID_NULL);
        }
    }
}